#--- PATH 
INC_DIR += ../../include ../
LIB_DIR = ../../lib

CSRCS     ?= $(wildcard *.cpp) $(wildcard *.cc)
CHDRS     ?= $(wildcard *.h)
COBJS     ?= $(addsuffix .o, $(basename $(CSRCS)))

CXX       = g++
CC        = gcc
AR        = ar cr

#--- include flag
DEPENDDIR = -I. $(addprefix -I, $(INC_DIR))

#--- option flag
OPTFLAG  = -O3 -DNDEBUG -s 
#OPTFLAG = -O2 -g 
#OPTFLAG  = -O2 -g -DNDEBUG -s
#OPTFLAG  =  -g 

WFLAG    = -Wall -Wno-unused-function 
FFLAG    = -fno-strict-aliasing -ffloat-store -fopenmp \
		   -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-cfree \
		   -fno-builtin-memalign -fno-builtin-posix_memalign -fno-builtin-valloc -fno-builtin-pvalloc -ftree-vectorize
CFLAGS   = $(OPTFLAG) $(WFLAG) $(FFLAG) $(PKGFLAG) -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS -DHAVE_CONFIG_H -DNO_TCMALLOC_SAMPLES -DNO_HEAP_CHECK -DNO_FRAME_POINTER

.PHONY: 

%.o : %.cpp
	@echo "> compiling: $< ... <"
	@$(CXX) $(CFLAGS) $(DEPENDDIR) -c -o $@ $<

%.o : %.cc
	@echo "> compiling: $< ... <"
	@$(CXX) $(CFLAGS) $(DEPENDDIR) -c -o $@ $<

%.o : %.c
	@echo "> compiling: $< ... <"
	@$(CC) $(CFLAGS) $(DEPENDDIR) -c -o $@ $<

top:target
	@echo ">processing $(PKGNAME) ...< "

clean::
	@echo ">clean $(PKGNAME) ...<"
	@rm -f *.o
	@rm -f depend.mak
	@rm -f $(TARGET)
	

depend.mak: $(CSRCS) $(CHDRS)
	@echo ">Making dependencies ...<"
	@for cpp in $(filter %.cpp, $(CSRCS));\
	do\
		$(CXX) -MM $(DEPENDDIR) -MT $${cpp/cpp/o} $$cpp >> $@;\
	done;\
	for cc in $(filter %.cc, $(CSRCS));\
	do\
		$(CXX) -MM $(DEPENDDIR) -MT $${cc/cc/o} $$cc >> $@;\
	done;\
	for c in $(filter %.c, $(CSRCS));\
	do\
		$(CC) -MM $(DEPENDDIR) -MT $${c/c/o} $$c >> $@;\
	done



-include depend.mak
